package com.oceansoft.core.common.util;

import org.apache.commons.lang.ArrayUtils;

/**
 * 异常处理类
 * 
 * @author Administrator
 * 
 */
public final class ExceptionUtil {
	public static boolean isCheckedException(Throwable throwable) {
		return ((!(throwable instanceof RuntimeException)) && (!(throwable instanceof Error)));
	}

	public static boolean isRuntimeException(Throwable throwable) {
		return throwable instanceof RuntimeException;
	}

	@SuppressWarnings("unchecked")
	public static boolean isCompatibleWithThrowsClause(Throwable throwable,
			@SuppressWarnings("rawtypes") Class[] declaredExceptions) {
		if ((declaredExceptions != null) && (!(ArrayUtils.isEmpty(declaredExceptions)))) {
			for (int i = 0; i < declaredExceptions.length; ++i) {
				if (declaredExceptions[i].isAssignableFrom(throwable.getClass())) {
					return true;
				}
			}
		}
		return false;
	}
}
